package com.text.aop;

import lombok.extern.java.Log;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Log//日志包，可以不要，用sout一样
@Aspect//AOP操作
@Component//bean
public class AopText {

    @Before("execution(* com.text.entry.Student.say(*))")
    public void before(JoinPoint joinPoint){
        System.out.println(Arrays.toString(joinPoint.getArgs()));
        log.info("这是say方法之前的日志");
    }

    @AfterReturning(value = "execution(* com.text.entry.Student.say(*))",returning = "obj")
    public void after(Object obj){
        System.out.println(obj);
        log.info("这是say方法之后的日志");
    }


    //    around方式，注意，around方法需要有返回值
    @Around("execution(* com.text.entry.Student.say(*))")
    public Object text(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("say方法执行之前的操作");
        Object proceed = joinPoint.proceed();
        System.out.println("say方法执行之后的操作");
        return proceed;
    }



}
